<template>
    <a-card :bordered="false">

        <!-- 操作按钮区域 -->
        <div class="table-operator">
            <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
        </div>

        <!-- table区域-begin -->
        <div>
            <a-table
                    ref="table"
                    size="middle"
                    :scroll="{x:true}"
                    bordered
                    rowKey="id"
                    :columns="columns"
                    :dataSource="dataSource"
                    :pagination="ipagination"
                    :loading="loading"
                    class="j-table-force-nowrap"
                    @change="handleTableChange">
                <span slot="action" slot-scope="text, record">
                    <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                      <a>删除</a>
                    </a-popconfirm>
                     <a-divider type="vertical"/>
                    <a :href="getAPKUrl(record.url)">下载</a>
                </span>
            </a-table>
        </div>

        <hc-application-version-modal :dataItem="dataItem" ref="modalForm"
                                      @ok="modalFormOk"></hc-application-version-modal>
    </a-card>
</template>

<script>

    import '@/assets/less/TableExpand.less'
    import { mixinDevice } from '@/utils/mixin'
    import { JeecgListMixin } from '@/mixins/JeecgListMixin'
    import HcApplicationVersionModal from './modules/HcApplicationVersionModal'
    import JSuperQuery from '@/components/jeecg/JSuperQuery.vue'
    import { getViewFileUrl } from '../../utils/util'

    export default {
        name: 'HcApplicationVersionList',
        mixins: [JeecgListMixin, mixinDevice],
        components: {
            HcApplicationVersionModal,
            JSuperQuery
        },
        props: ['dataItem'],
        data() {
            return {
                // 表头
                columns: [
                    {
                        title: '序号',
                        dataIndex: '',
                        key: 'rowIndex',
                        width: 60,
                        align: 'center',
                        customRender: function(t, r, index) {
                            return parseInt(index) + 1
                        }
                    },
                    {
                        title: '版本',
                        align: 'center',
                        dataIndex: 'version'
                    },
                    {
                        title: '应用类型',
                        align: 'center',
                        dataIndex: 'type',
                        customRender: function(t, r, index) {
                            if (t === 1) {
                                return 'android'
                            }
                            return 'ios'
                        }
                    },
                    {
                        title: '下载地址',
                        align: 'center',
                        dataIndex: 'url'
                    },
                    {
                        title: '应用更新说明',
                        align: 'center',
                        dataIndex: 'remark'
                    },
                    {
                        title: '创建时间',
                        align: 'center',
                        dataIndex: 'createTime',
                        customRender: function(text) {
                            return !text ? '' : (text.length > 10 ? text.substr(0, 10) : text)
                        }
                    },
                    {
                        title: '创建人',
                        align: 'center',
                        dataIndex: 'createBy'
                    },
                    {
                        title: '操作',
                        dataIndex: 'action',
                        align: 'center',
                        width: 147,
                        scopedSlots: { customRender: 'action' }
                    }
                ],
                url: {
                    list: '/hc/hcApplicationVersion/getApplicationVersionList',
                    delete: '/hc/hcApplicationVersion/delete'
                },
                disableMixinCreated: true,
                superFieldList: []
            }
        },
        created() {
            this.getSuperFieldList()
        },
        methods: {
            initDictConfig() {
            },
            getAPKUrl(url){
                return getViewFileUrl(url);
            },
            getSuperFieldList() {
                if (this.dataItem) {
                    this.queryParam = {
                        applicationId: this.dataItem.id
                    }
                    this.loadData()
                }
                let fieldList = []
                fieldList.push({ type: 'int', value: 'type', text: '应用类型1android,2ios', dictCode: '' })
                fieldList.push({ type: 'string', value: 'remark', text: '应用更新说明', dictCode: '' })
                this.superFieldList = fieldList
            }
        }
    }
</script>
<style scoped>
    @import '~@assets/less/common.less';
</style>
